<?php
session_start();
include '../c/config.php';
$openid='';
if (isset($_GET['op'])){
    $openid=$_GET['op'];
    $_SESSION['openid']=$openid;
    
    header('Location: http://climb-game.51wom.com/zhuan/');	
    exit;
}
if (isset($_SESSION['openid'])){
    $openid=$_SESSION['openid'];
}else{
   $redirect_uri = urlencode('http://climb-game.51wom.com/zhuan/b1.php');
   $api_userinfo_base='https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appId.'&redirect_uri='.$redirect_uri.'&response_type=code&scope=snsapi_base#wechat_redirect';
        
   header('Location: '.$api_userinfo_base);	
   exit;
}
$url='.';
//$url='https://tu-10030004.file.myqcloud.com/szds';
$uid='';
$mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $dbName);
$queryG=$mysqli->query("select id from zuansu_user where openid='".$openid."'  limit 0, 1");
if($queryG->num_rows>0){
   $getD=$queryG->fetch_assoc();
   $uid=$getD['id'];
}
$mysqli->close();

include '../jssdk.php';
$jssdk = new JSSDK($appId, $secret);
$signPackage = @$jssdk->GetSignPackage();

?><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<title>专属活动链接申请</title>
<style>
html,body{font-size:16px;width:100%;font-size:12px;color:#000000;font-family:Microsoft YaHei, Gotham, "Helvetica Neue", Helvetica, Arial, sans-serif;}
body, div{position:relative;padding:0px;margin:0px auto;max-width:750px;}
.weui-mask{position:fixed;z-index:1000;top:0;right:0;left:0;bottom:0;background:rgba(0,0,0,0.6)}
.weui-dialog{position:fixed;z-index:5000;top:50%;left:16px;right:16px;-webkit-transform:translate(0,-50%);transform:translate(0,-50%);background-color:#fff;text-align:center;border-radius:12px;overflow:hidden;display:-webkit-box;display:-webkit-flex;display:flex;-webkit-flex-direction:column;-webkit-box-orient:vertical;-webkit-box-direction:normal;flex-direction:column;max-height:90%}
@media screen and (min-width:352px){.weui-dialog{width:320px;margin:0 auto}
}.weui-dialog__bd:first-child{min-height:40px;padding:32px 24px 0;font-weight:700;color:rgba(0,0,0,0.9);display:-webkit-box;display:-webkit-flex;display:flex;-webkit-flex-direction:column;-webkit-box-orient:vertical;-webkit-box-direction:normal;flex-direction:column;-webkit-box-pack:center;-webkit-justify-content:center;justify-content:center}
.weui-dialog__bd{overflow-y:auto;-webkit-overflow-scrolling:touch;padding:0 24px;margin-bottom:32px;font-size:17px;line-height:1.4;word-wrap:break-word;-webkit-hyphens:auto;hyphens:auto;color:rgba(0,0,0,0.5)}
.weui-dialog__ft{position:relative;display:-webkit-box;display:-webkit-flex;display:flex;width:100%}
.weui-dialog__btn{-webkit-box-flex:1;-webkit-flex:1;flex:1;display:block;line-height:1.41176471;padding:16px 0;font-size:17px;color:#576b95;font-weight:700;text-decoration:none;-webkit-tap-highlight-color:rgba(0,0,0,0);position:relative;overflow:hidden}
.weui-dialog__ft:after{content:" ";position:absolute;left:0;top:0;right:0;height:1px;border-top:1px solid rgba(0,0,0,0.1);color:rgba(0,0,0,0.1);-webkit-transform-origin:0 0;transform-origin:0 0;-webkit-transform:scaleY(0.5);transform:scaleY(0.5)}
-webkit-touch-callout:none;
-webkit-user-select:none;
html{-ms-touch-action:none;}
div,img{-webkit-tap-highlight-color:rgba(0,0,0,0);}
*{-webkit-text-size-adjust: none;}
.simg{position:absolute;display:block;}
a{text-decoration:none;}
.txt{position:absolute;text-indent:8px;font-size:12px;z-index:2;border:none;background:transparent;}
.txt::-webkit-input-placeholder {color:#a0a09b;text-align:left;}
input {
    outline:none;
    border:none;
    outline-color: "red";
    -webkit-transform: translate3d(0, 0, 0);
}
select{position:absolute;display:block;background:transparent;border:0px;text-indent:8px;font-size:12px;-webkit-appearance:none;}
input:-internal-autofill-selected, .txt:-internal-autofill-selected{background:transparent;}
.container{position:relative;width:100%;height:auto;overflow-x:hidden;}
.p1{opacity:0;}
.p2-txt{position:absolute;font-size:13px;text-align:center;color:#000;}
.fade-in{opacity:1;-webkit-transition:opacity 1s ease-in-out;-moz-transition: opacity 1s ease-in-out;-o-transition: opacity 1s ease-in-out;transition: opacity 1s ease-in-out;}
.p-bg{top:0px;left:0px;}
.l100{position:absolute;width:100%;left:0;display:block;}
.p-b, .thebg{position:absolute;width:100%;top:0;left:0;} 
.t-bg{position:absolute;display:none;width:100%;height:100%;top:0;left:0;background-color:#000;opacity:.8;z-index:9;}
.page{position:absolute;display:none;width:100%;height:100%;top:0;left:0;}
.p1-1{top:0;}
.hide{display:none;}
.p1-jr{z-index:6;}
.user-link, .user-copy{position:absolute;height: 20px;line-height: 20px;}
.user-link{left:1%;width: 80%;font-size:0.3rem;top:8.4%;}
.user-copy{width:90%;right:3.4%;text-align:right;font-size:0.3rem;color:#0371be;top:8.38%;}
.share{background:rgba(0,0,0,.8);}
.share-1{top:1%;}
@media (max-width: 360px){ 
   .user-link, .user-copy{font-size:0.27rem;}
}
</style></head>
<body>
<div class="container">

  <div class="p1 page">
      <div class="thebg">
        <img class="l100 p1-1" src="<?php echo $url; ?>/img/p1-t1.jpg" />
        <input id="p1-phone" class="txt" name="p1-phone" type="text" value="" placeholder="请输入" />
        <input id="p1-ncid" class="txt" name="p1-ncid" type="text" value="" placeholder="请输入" />
        <div class="p1-jr simg"></div>
     </div>
  </div>

  <div class="user page">
  	   <img class="l100 user-1" src="<?php echo $url; ?>/img/user-t1.jpg?v=3" />
  	   <div class="user-link">http://climb-game.51wom.com/?zslink=<?php echo $uid; ?></div>
  	   <div class="user-copy" data-clipboard-text="http://climb-game.51wom.com/?zslink=<?php echo $uid; ?>">复制链接</div>
  	   <div class="user-jin simg" data-clipboard-text="http://climb-game.51wom.com/?zslink=<?php echo $uid; ?>"></div>
       <div class="user-cha simg"></div>
  </div>

  <div class="share page">
  	  <img class="l100 share-1" src="<?php echo $url; ?>/img/share.png" />
  </div>


  <div class="js_dialog"  id="iosDialog2" style="display:none;">
            <div class="weui-mask"></div>
            <div class="weui-dialog">
                <div class="weui-dialog__bd"></div>
                <div class="weui-dialog__ft">
                    <a role="button" href="javascript:" class="weui-dialog__btn weui-dialog__btn_primary">确认</a>
                </div>
            </div>
  </div>
  
    
    
  
</div>
<script src="https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.0.0/jquery.min.js"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script src="./js/clipboard.min.js"></script>
<script>
_h=h= Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
var sWidth = parseInt((window.innerWidth > 0) ? window.innerWidth : screen.width);
if(sWidth>750){sWidth=750;}
var _rate=(sWidth/750);
if(h<_rate*1246){
    h=_rate*1246;
}
function window_fontResize(e){
	font_resize();
	setFrameout(font_resize,10);
}//edn func
function font_resize(){
	var size=document.documentElement.clientWidth / 750 * 100;
	document.querySelector('html').style.fontSize=size + 'px';
}
function setFrameout(callback, frame) {
		frame=frame||0;
		var now = 0;
		timer_handler();
		function timer_handler() {
			now++;
			var timeup = now >= frame;
			if(timeup) callback();
			else requestAnimationFrame(timer_handler);
		} //end func
	}
var _link='http://climb-game.51wom.com/';
$(function(){
	<?php if(!empty($uid)){ ?>
	//var _link='http://climb-game.51wom.com/?zslink=<?php echo $uid; ?>';	
    $(".user").show().addClass("fade-in");
<?php }else{ ?>
    $(".p1").show().addClass("fade-in");
<?php }  ?>
    $('.p-b').height(_rate*1206);
    $('.container, .page').width(sWidth).height(h);
    $('.p1-jr').width(_rate*250).height(_rate*120).css({"top":_rate*870, "left":_rate*236});
      
    $('#p1-phone').width(_rate*566).height(_rate*90).css({"top":_rate*6, "left":_rate*156});
    $('#p1-ncid').width(_rate*566).height(_rate*90).css({"top":_rate*104, "left":_rate*156});
    $('.p1-jr').width(_rate*650).height(_rate*110).css({"top":_rate*280, "left":_rate*50});
    
    $('.user-jin').width(_rate*650).height(_rate*110).css({"top":_rate*360, "left":_rate*50});
    $('.user-cha').width(_rate*650).height(_rate*110).css({"top":_rate*470, "left":_rate*50});
    
    font_resize(); 
    window.addEventListener("resize", window_fontResize, false);
    
    $('.p1-jr').click(function(){
       var _phone=$('#p1-phone').val();
       var _ncid=$('#p1-ncid').val();
       if ('' == _phone) {
         _popMsg('请输入手机号');
       	 return;
       }
       if ('' == _ncid) {
         _popMsg('请输入NCID');
       	 return;
       }
       $.post("./api/?c=getlink", {ph:_phone, ncid:_ncid,op:'<?php echo $openid ?>'}, function(data){
          console.log(data);
          if('y' == data.s){
          	  $(".user-link").html(data.link);
              $(".user-copy, .user-jin").attr('data-clipboard-text', data.link);
              $(".p1").hide();
              $(".user").show();
              //_link=data.link;
          }else{
            _popMsg('手机号和NCID不匹配，请检查后重新输入。如遗忘信息可线下联系您的上级领导进行查证和修正。');
          }
       }, "json"); 


    });
    
function _popMsg(_msg){
	$(".js_dialog .weui-dialog__bd").html(_msg);
	$(".js_dialog").show();
}
$(".weui-dialog__btn").click(function(){
	$(".js_dialog").hide();
});
var clipboard = new ClipboardJS('.user-copy');
clipboard.on('success', function(e) {
	_popMsg('已复制链接，直接分享链接同样记录分享业绩');
    e.clearSelection();
});

var _link='http://climb-game.51wom.com/?f=<?php echo $openid; ?>';
wx.config({
    appId: '<?php echo $signPackage["appId"];?>',
    timestamp: <?php echo $signPackage["timestamp"];?>,
    nonceStr: '<?php echo $signPackage["nonceStr"];?>',
    signature: '<?php echo $signPackage["signature"];?>',
    jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData', 'showMenuItems', 'hideMenuItems']
});
wx.ready(function () {
		var _imgUrl='http://climb-game.51wom.com/images/64.jpg';
			wx.updateAppMessageShareData({
			    title: '美赞臣', 
			    desc: '专属活动链接分享', 
			    link: _link, 
			    imgUrl: _imgUrl, 
			    success: function () {
			    }
			  })
			 wx.updateTimelineShareData({ 
                  title: '专属活动链接分享', 
                  link: _link, 
                  imgUrl: _imgUrl, 
                  success: function () {
                  }
                });
});
$(".user-jin").click(function(){
	$(".share").fadeIn();
    

	var _imgUrl='http://climb-game.51wom.com/images/64.jpg';
		wx.updateAppMessageShareData({
		    title: '美赞臣', 
		    desc: '专属活动链接分享', 
		    link: _link, 
		    imgUrl: _imgUrl, 
		    success: function () {
		    }
		  })
		 wx.updateTimelineShareData({ 
              title: '专属活动链接分享', 
              link: _link, 
              imgUrl: _imgUrl, 
              success: function () {
              }
            });

});
$(".share").click(function(){
	$(".share").hide();
});

    
});
</script>
</body>
</html>